﻿// Copyright © 2012 Liversage Consulting A/S
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

using System;
using Microsoft.Win32;

namespace Liversage.AllCapsMenuOption {

  public static class RegistrySetting {

    const String Path = @"Software\Microsoft\VisualStudio\11.0\General";

    const String Name = "SuppressUppercaseConversion";

    public static Boolean Get() {
      using (var key = Registry.CurrentUser.OpenSubKey(Path)) {
        if (key == null)
          return true;
        var value = key.GetValue(Name);
        if (value == null)
          return true;
        if (value.GetType() != typeof(Int32))
          return true;
        var intValue = (Int32) value;
        return intValue == 0;
      }
    }

    public static void Set(Boolean value) {
      using (var key = Registry.CurrentUser.CreateSubKey(Path)) {
        if (key == null)
          return;
        if (value && key.GetValue(Name) != null)
          key.DeleteValue(Name);
        else
          key.SetValue(Name, 1, RegistryValueKind.DWord);
      }
    }
     
  }

}